{include file="public/head" /}

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span>商品名</label>
                    <div class="layui-input-inline">
                        <input type="text" id="name" name="name" required="" lay-verify="required" autocomplete="off"
                            class="layui-input" value="{$res.name}"></div>
                    <input type="hidden" id="id" name="id" required="" lay-verify="required" autocomplete="off"
                        class="layui-input" value="{$res.id}">
                </div>
        </div>
        <div class="layui-form-item">
            <label for="stock" class="layui-form-label">
                <span class="x-red">*</span>封面图片</label>
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" id="test1">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                    预览图：
                    <div class="layui-upload-list" id="demo7">
                        <img style='height:150px' src="{$res.img}" class='layui-upload-img' id="imgid">
                        <input type='hidden' class='input-text' value="{$res.img}" placeholder='' name='imgs'
                            id="imgval">
                    </div>
                </blockquote>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="score" class="layui-form-label">
                <span class="x-red">*</span>兑换积分</label>
            <div class="layui-input-inline">
                <input type="text" id="score" name="score" required="" lay-verify="required|number" autocomplete="off"
                    class="layui-input" value="{$res.score}"></div>
        </div>

        <div class="layui-form-item">
            <label for="stock" class="layui-form-label">
                <span class="x-red">*</span>库存</label>
            <div class="layui-input-inline">
                <input type="text" id="stock" name="stock" required="" lay-verify="required|number" autocomplete="off"
                    class="layui-input" value="{$res.stock}"></div>
        </div>
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="x-red">*</span>状态</label>
            <div class="layui-input-inline">
                <input type="checkbox" name="status" lay-skin="primary" title="开启">
            </div>


            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="*" lay-submit>修改</button></div>
            </form>
        </div>
    </div>
    <script>layui.use(['form', 'layer'],
            function () {
                $ = layui.jquery;
                var form = layui.form
                    , layer = layui.layer
                    , layedit = layui.layedit
                    , laydate = layui.laydate;

                //监听提交
                form.on('submit(*)',
                    function (data) {
                        console.log(data);
                        //发异步，把数据提交给php

                        $.ajax({
                            type: "POST",
                            url: "{:url('edit')}",
                            data: {
                                'id': data.field.id,
                                'name': data.field.name,
                                'score': data.field.score,
                                'stock': data.field.stock,
                                'status': data.field.status,
                                'img': data.field.imgs
                            },
                            dataType: "json",
                            success: function (data) {
                                // var obj = eval(data);
                                console.log(data)
                                layer.alert(data.msg, {
                                    icon: 6
                                },
                                    function () {
                                        // 获得frame索引
                                        var index = parent.layer.getFrameIndex(window.name);
                                        //关闭当前frame
                                        parent.layer.close(index);
                                    }
                                );


                            }
                        });


                        return false;
                    });

            });</script>

    <!-- 
    <script>
        layui.use('upload', function () {
            var upload = layui.upload;

            //执行实例
            var uploadInst = upload.render({
                elem: '#test1' //绑定元素
                ,accept: 'images' 
                ,acceptMime: 'image/*'
                ,exts:'jpg|png|gif|bmp|jpeg'
                , url: "{:url('admin/api/upload')}" //上传接口
                , done: function (res) {
                    //上传完毕回调
                    console.log(res)
                }
                , error: function () {
                    //请求异常回调
                }
            });
        });
    </script> -->

    <script>
        layui.use('upload', function () {
            var $ = layui.jquery,
                upload = layui.upload;

            //多图片上传
            upload.render({
                elem: '#test1',
                url: "{:url('admin/api/upload')}" //改成您自己的上传接口
                ,
                exts: 'jpg|png|gif|bmp|jpeg',
                multiple: true,

                done: function (res) {
                    //上传完毕
                    console.log(res)

                    $('#imgid').attr('src', res.data.src);
                    $('#imgval').val(res.data.src)

                }
            });

        });
    </script>

</body>

</html>